/**
	Utility class for TextFields

	@author Chandler McWilliams
	@version 2007-01-19
*/
class timber.util.TextFieldUtil
{
		
	public static function clearOnFocus(field:TextField, always:Boolean):Void {
		var ears = {};
		ears.field = field;
		ears.always = (always == undefined)?false:always;
		ears.onSetFocus = function(){
			if(eval(Selection.getFocus()) == this.field){
				if (field.html) {
					field.htmlText = '';
				} else {
					field.text = '';
				}
				if (!this.always) Selection.removeListener(this);
			}
		}
		Selection.addListener(ears);
	}
	
	
	public static function addOnEnter(field:TextField, callback:Function):Void {
		var ears = new Object();
		ears.field = field;
		ears.callback = callback;
		ears.onKeyDown = function () {
			if (eval(Selection.getFocus()) == this.field && (Key.getCode() == Key.ENTER)) {
				callback(this.field);
			}
		}
		Key.addListener(ears);
	}
}